windywhale.com

Simulating Artificial Animals with Neural Networks

Project Summary

This piece of software was created to showcase a basic neural network in C++. The application allows the user to view how a neural network is trained over generations to look for food to survive.


Personal Writeup

One day, I was scrolling youtube like any other normal saturday. I stumbled upon an armada of youtube videos covering the simulation of artificial life and evolutionary behaviour. These videos ranged from virtual evolving creatures to the evolution of digital trees. Not all of them used neural networks, as I found some used other ways such as cellular automata or algorithms to achieve a form of digital life. My first attempt at creating the simulation about 2 weeks, which ended up not working in the long run. My code quality was inflexible and hard to manage and the creatures were not training for some reason. Using the dot product of the angle of the animal direction and angle needed to face the food caused the creatures to actually work! The dot product turns 2 Vector2s into a single value. The value in our case compares how similarly the 2 angles are. By using that as an input instead of a raw radian, the animals soon learned. By the end, I had a full working simulation. I hope to talking some more complicated neural network layouts or cellular automata that actually simulates plantgrowth or life.

Image of Program

Screenshot of the program


Documentation

Simulation Controls

File Controls

Sample Import GUI Sample Export GUI

Sample of Import GUI

Sample of Export GUI

Statistics

Statistics GUI

Sample of information GUI

Animal Structure

Animals in simulation

Screenshot of 2 animals searching for food

The first value is health while the 2nd one is the fitness value. The fitness value determines the overall success the animal had at getting food. Once health reaches zero, they die.

Brain graph

This graph shows the brainwave of the best performing animal

The output of the animal's brain determine how it moves around our area.


Specifications

C++
Raylib
Visual Studio
Imgui
1000x1000 Resolution
Windows 10 and 11 Tested

Download

Click for EXE!